package ace.cmp.spring.data.jdbc.querydsl.rsql.core;

import com.querydsl.core.types.Predicate;
import com.querydsl.sql.RelationalPath;
import cz.jirutka.rsql.parser.ast.AndNode;
import cz.jirutka.rsql.parser.ast.ComparisonNode;
import cz.jirutka.rsql.parser.ast.OrNode;
import cz.jirutka.rsql.parser.ast.RSQLVisitor;

/**
 * @author caspar
 * @date 2023/4/14 9:24
 */
public class RsqlQuerydslVisitor implements RSQLVisitor<Predicate, Void> {

  private final RsqlQuerydslFactory factory;

  public RsqlQuerydslVisitor(Class... entityTypes) {
    this.factory = new RsqlQuerydslFactory(entityTypes);
  }

  public RsqlQuerydslVisitor(RelationalPath<?>... relationalPaths) {
    this.factory = new RsqlQuerydslFactory(relationalPaths);
  }

  public RsqlQuerydslVisitor(RsqlQuerydslFactory factory) {
    this.factory = factory;
  }

  @Override
  public Predicate visit(AndNode node, Void param) {
    return factory.create(node);
  }

  @Override
  public Predicate visit(OrNode node, Void param) {
    return factory.create(node);
  }

  @Override
  public Predicate visit(ComparisonNode node, Void param) {
    return factory.create(node);
  }
}
